/* @(#)UploadFiles.java    V1.0
 *
 * Project: APEP 
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   wangp    {CREATE_TIME} First release
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2007 Auto-Parts E-Procurement Co., Ltd. 
 *        No.251-1 Wuning Road, Shanghai, 200063, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Auto-Parts E-Procurement Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with APEP.
 *
 * Warning:
 * =============================================================================
 *   
 * 
 */

package com.apep.gw.synch;

import com.apep.gw.data.UploadFilesBase;

import framework.core.Conditions;
import framework.core.DBConnection;
import framework.core.DBEngine;
import framework.core.DBResult;
import framework.core.DateUtil;
import framework.core.LogWriter;

/*
 * Author :wangp CreateTime:{CREATE_TIME}
 */
public class UploadFiles extends UploadFilesBase {

    // ----system generated start----//
    public static final int NOT_EXCUTED = 0;
    public static final int EXCUTED = 1;
    
    private static final String SEQ_NAME = "S_UPLOAD_FILES";

    public UploadFiles() {

    }

    private static void delete(DBConnection con, int id) throws Exception {
        Conditions conditions = new Conditions();

        conditions.add(ID, id);

        delete(con, TABLE_NAME, conditions);
    }

    public static UploadFiles fetch() {
        return new UploadFiles();
    }

    public static UploadFiles copy(UploadFiles srcObj) {
        UploadFiles obj = fetch();
        obj.copyBase(srcObj);
        return obj;
    }

    public static UploadFiles fetch(DBConnection con, int id) throws Exception {
        Conditions conditions = new Conditions();

        conditions.add(ID, id);

        return fetch(con, conditions);
    }

    public static UploadFiles fetch(DBConnection con, Conditions conditions) throws Exception {
        DBResult result = null;
        try {
            result = DBEngine.doSelect(con, "select * from " + TABLE_NAME, conditions);
            java.sql.ResultSet rs = result.getRs();
            UploadFiles obj = null;
            if (rs.next()) {
                obj = fetch(rs);
            }
            return obj;
        } finally {
            if (result != null)
                result.clear();
        }
    }

    public static UploadFiles fetch(java.sql.ResultSet rs) throws Exception {
        UploadFiles obj = new UploadFiles();
        obj.initObject(rs);
        return obj;
    }

    protected void getUnique(DBConnection con) throws Exception {
        setId(DBEngine.getId(con, SEQ_NAME));
    }
    //----system generated end----//

    
    /**
     * 新增记录
     */
    public static void save(String warehouseId, String fileName, String filePath, String fileType, int fileLength) throws Exception {
        DBConnection con = null;
        
        try {
            con = DBConnection.open();
            con.setAutoCommit(false);
            UploadFiles tUploadFiles = UploadFiles.fetch();
            tUploadFiles.setWarehouseId(warehouseId);
            tUploadFiles.setFileName(fileName);
            tUploadFiles.setFilePath(filePath);
            tUploadFiles.setFileType(fileType);
            tUploadFiles.setFileLength(fileLength);
            tUploadFiles.setCreateTime(new DateUtil().getFullString());
            tUploadFiles.setIsExcute(NOT_EXCUTED);
            tUploadFiles.save(con);
            con.commit();
        } catch(Exception e) {
            con.rollback();
            LogWriter.error(e.getLocalizedMessage(), e);
        } finally {
            if(con != null)
                con.close();
        }
        
    }
}
